# -*- coding: utf-8 -*-
"""
# @Time    : 2021/1/7 下午1:54
# @Author  : tgy
# url      : https://leetcode-cn.com/problems/n-queens-ii/
"""


class Solution:
    ...

    def totalNQueens(self, n):
        ...
        """
        queens_locs 存放第row行存在queens_locs[row]列位置
        """
        queens_locs = [0] * n
        self.count = 0
        self.queen_display(queens_locs, 0)
        return self.count

    def queen_display(self, queens_locs, row):
        ...
        if row == len(queens_locs):
            self.count += 1
            return

        for i in range(len(queens_locs)):
            ...
            if self.is_display(queens_locs, row, i):
                queens_locs[row] = i
                self.queen_display(queens_locs, row+1)


    def is_display(self, queens_locs,row, col):

        for i in range(row):
            if queens_locs[i] == col or \
                    abs(i - row) == abs(col - queens_locs[i]):
                return False

        return True

if __name__ == '__main__':
    ...
    solution = Solution()
    queens = solution.totalNQueens(9)
    print(queens)
